package com.gitee.srurl.core.exception;

import com.gitee.srurl.core.enums.ResponseCodeEnums;

import java.io.Serial;

/**
 * @author zxw
 * @date 2023/4/9 17:02
 */
public class ServiceException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 647365996380415688L;

    protected Integer code;

    protected String message;

    public ServiceException() {
        super();
        this.code = ResponseCodeEnums.GLOBAL_ERROR.code();
        this.message = "系统异常";
    }

    public ServiceException(String message) {
        super(message);
        this.message = message;
        this.code = ResponseCodeEnums.GLOBAL_ERROR.code();
    }

    public ServiceException(ResponseCodeEnums responseCodeEnums) {
        super(responseCodeEnums.message());
        this.message = responseCodeEnums.message();
        this.code = responseCodeEnums.code();
    }

    public ServiceException(int code) {
        super("系统异常！");
        this.code = code;
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.code = ResponseCodeEnums.GLOBAL_ERROR.code();
    }

    public ServiceException(Throwable cause) {
        super(cause);
        this.code = ResponseCodeEnums.GLOBAL_ERROR.code();
    }

    public ServiceException(String message, int code) {
        super(message);
        this.message = message;
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }
}
